﻿using System;
using System.Windows.Data;

namespace GroupChallenge.Converters
{
    public class BoolWithIntParameterConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter == null)
                return false;

            return value.ToString() == parameter.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            object ret = value;

            if (value is bool &&
                (bool)value == true)            // Only return the current id if selected-true.
            {
                int temp = 0;

                int.TryParse(parameter as string, out temp);

                ret = temp;
            }

            return ret;
        }
    }
}
